<?php
session_start();
$url = 'http://localhost/mathRomp/addUsers.php';

$numStudents = $_SESSION['numStudents'];
$numQuestions = $_SESSION['numQuestions'];
$assignId = $_SESSION['assignId'];
$assignment = "{\"assignment\":[";

if($_POST['add'] == "submit"){
  header("Location: $url");
}

echo '<html>
   <head>
      <title>Create New Assignment</title>
   </head>
   <body>
      <h1>Create New Assignment</h1>
       <form action="addProblems.php" method="post" name="maint"
   id="maint">
         <fieldset class="maintform">
            <legend>Add Problems</legend>';

for($i=0; $i<$numQuestions; $i++){
  echo '<li><label class="required">Question '.($i+1).'</label><br />
<input type="text" name="question'.$i.'" id="question'.$i.'" class="required"/></li><br />';
}

for($i=0; $i<$numQuestions; $i++){
  $question = $_REQUEST['question'.$i.''];
  if(strpos($question, '<frac>') !== FALSE){
    $question = str_replace('+', 'plus', $question);
    $question = str_replace('-', 'minus', $question);
    $question = str_replace('*', 'times', $question);
    $question = str_replace('/', 'divides', $question);
  }
  if(strpos($question, '<exp>') !== FALSE){
    $question = str_replace('*', 'eMult', $question);
    $question = str_replace('/', 'eDiv', $question);
  }
  $assignment .= "{\"template\":\"".$question."\"}";
  if($i < ($numQuestions-1)){
    $assignment .=",";
  }
}

$assignment .= "]}";

$_SESSION['assignment'] = $assignment;



echo '<button type="submit" value="submit" name="add">Next</button>
      </form>
      </body>
      </html>';
